/**
 * 资源管理数据列表页JS
 * User: fengchuang
 * Date: 15-8-17
 * Time: 下午5:58
 * To change this template use File | Settings | File Templates.
 */
$(function(){
    //激活左侧导航菜单
    activeNavBar("MANAGER_DISTRICT_INFO");
    initSelect2();
    loadResourceTree();

    $("#expandAllBtn").click(function(){
        $.fn.zTree.getZTreeObj("tree").expandAll(true);
        $("#expandAllBtn").addClass("hide");
        $("#foldAllBtn").removeClass("hide");
    });

    $("#foldAllBtn").click(function(){
        $.fn.zTree.getZTreeObj("tree").expandAll(false);
        $("#expandAllBtn").removeClass("hide");
        $("#foldAllBtn").addClass("hide");
    });
});

var zTree;
/**
 * 加载资源树
 */
function loadResourceTree(){

    var setting = {
        data: {
            key: {
                name: "districtName"
            },
            simpleData: {
                enable: true,
                idKey: "districtCode",
                pIdKey: "parentDistrictCode"
            }
        }
    };

    var zNodes;

    function initTreeNode(data){
        zNodes = data;
        $.fn.zTree.init($("#tree"), setting, zNodes);
        zTree = $.fn.zTree.getZTreeObj("tree");
        zTree.expandAll(false);
    };

    jQuery.ajax({
        type:"post",
        cache:false,
        dataType:'json',
        url:springUrl + "/web/districtInfo/list",
        success:function (data) {
            initTreeNode(data);
        },
        error : function(data){
            Alert.error("初始化页面数据失败!");
        }
    });
}